/*
 * @Description  : 自定义路由监听
 * @Date         : 2021-08-20 14:16:25
 * @Author       : 保锋
 * @LastEditTime : 2021-08-26 10:39:05
 * @LastEditors  : 保锋
 * @FilePath     : \flutter_demo\lib\routes\myroute.dart
 */
import 'package:flutter/material.dart';

class MyRouteObserver<R extends Route<dynamic>> extends RouteObserver<R> {
  @override
  void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
    super.didPush(route, previousRoute);
    print('路由前进 当前路由: ${route.settings},上一条路由:${previousRoute?.settings}');
  }

  @override
  void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
    super.didPop(route, previousRoute);
    print('路由后退 当前路由: ${route.settings},上一条路由:${previousRoute?.settings}');
  }

  @override
  void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) {
    super.didReplace(newRoute: newRoute, oldRoute: oldRoute);
    print('替换路由 新路由: ${newRoute?.settings},旧路由:${oldRoute?.settings}');
  }

  @override
  void didRemove(Route<dynamic> route, Route<dynamic>? previousRoute) {
    super.didRemove(route, previousRoute);
    print('删除路由 当前路由: ${route.settings},上一条路由:${previousRoute?.settings}');
  }

  @override
  void didStartUserGesture(
      Route<dynamic> route, Route<dynamic>? previousRoute) {
    super.didStartUserGesture(route, previousRoute);
    print('用户手势开始 当前路由: ${route.settings},上一条路由:${previousRoute?.settings}');
  }

  @override
  void didStopUserGesture() {
    super.didStopUserGesture();
    print('用户手势结束');
  }
}
